package simple

import "strings"

func longestCommonPrefix(str []string) string {
	l := len(str)
	if l == 0 {
		return ""
	}
	prefix := str[0]
	for i := 1; i < l; i++ {
		for !strings.HasPrefix(str[i], prefix) {
			prefix = prefix[:len(prefix)-1]
			if prefix == "" {
				return ""
			}
		}
	}
	return prefix
}
